<div id="lib_Tab1">
	<div><h2><?=$dbId?>导出操作</h2></div>
	<div class="lib_Menubox lib_tabborder">
		<ul>
		<?php 
		$n = 1;
		$count = count($back);
		foreach ($back as $key => $value){
			echo "<li id=\"one{$n}\" onclick=\"setTab('one','{$n}','{$count}')\" class=\"hover\">{$key}</li>";
			$n++;
		}
		?>
		</ul>
	</div>
	<div class="lib_Contentbox lib_tabborder">  
	<?php 
	$n = 1;
	$html = '';
	foreach ($back as $key => $value){
		$is_show = '';
		$is_checked = '';
		if ($n != 1) {
			$is_show = "style='display:none'";
		}else {
			$is_checked = 'checked';
		}
		$html .= "<div id=\"con_one_{$n}\" {$is_show}><form><table width=\"400\" align=\"left\" cellpadding=\"0\" cellspacing=\"0\" id=\"myTable\"><tr><th><input name='chkAll' type='checkbox' id='chkAll' onclick='CheckAll(this.form)' value='checkbox'> 全选</th><th>表名</th></tr>";
		foreach ($value as $k => $val){
			$html .= "<tr><td><input type='checkbox' name='dbids_{$n}' value='{$val}' {$is_checked}/></td><td>{$val}</td></tr>";			
		}
		$html .= "<tr><td colspan='2'>(<input type='checkbox' id='table_{$n}' value='table'/>结构&nbsp;<input type='checkbox' id='data_{$n}' value='data'/>数据)<a href='#' onclick=\"dataExport('export', '{$dbId}', '{$n}');\" >导出选中的表</a>&nbsp;&nbsp;<a href='#' onclick=\"if(confirm('确定清除吗?')) dataExport('empty', '{$dbId}', '{$n}'); \">清空选中的表</a></td></tr>";
		$html .= "</table></form></div>";
		$n++;
	}
	echo $html;
	?> 
	</div>
</div>

</body>
<script type="text/javascript" >
//导出数据
function dataExport(type, dbId, n){
	var t;
	if (type == 'empty'){
		t = prompt('请输入密钥');
	}
	if (type == 'export' && !$("[id=table_"+n+"][checked]").val() && !$("[id=data_"+n+"][checked]").val()){
		alert('请选择备份类型!');
		exit();
	}
	
	var str="";
	$("[name='dbids_"+n+"'][checked]").each(function(){
		str+=$(this).val()+"|";
	})

	$.ajax({
		type:'POST',
		timeout:180000,	
		url:'ajax/comparedb.ajax.php',			
		data:"act="+type+"&dbId="+dbId+"&tables="+str+"&table="+$("#table_"+n+"[checked]").val()+"&data="+$("#data_"+n+"[checked]").val()+"&key="+t,
		beforeSend:function () {
			$('#loaddiv').show();			
		},		
		success:function(msg){
			if (msg == '请选择要备份的表'){
				alert(msg);
			}else{				
				$('#viewdb').html(msg);
			}
			$('#loaddiv').hide();
		},
		error:function(){
			alert('超时了，请检查服务器设置是否正确！');
			$('#loaddiv').hide();
			return;
		}
	})
}

function setTab(name,cursel,n){
	for(i=1;i<=n;i++){
		var menu=document.getElementById(name+i);
		var con=document.getElementById("con_"+name+"_"+i);
		menu.className=i==cursel?"hover":"";
		con.style.display=i==cursel?"block":"none";
	}
}

</script>